package com.ailight.smart.ai.factory;

import com.ailight.smart.ai.enums.AiModelEnum;
import com.ailight.smart.ai.strategy.AiModelStrategy;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author: 朱海鹏
 * @Package: com.ailight.smart.ai.factory
 * @Project: ai-light
 * @date: 2025/3/19 10:39
 * @description :
 */
@Component
public class AiModelFactory implements ApplicationContextAware {

    private final Map<Integer,AiModelStrategy> factories = new ConcurrentHashMap<>();

    @Override
    public void setApplicationContext(@NotNull ApplicationContext applicationContext) throws BeansException {
        for (AiModelEnum modelEnum : AiModelEnum.values()) {
            if (modelEnum.isEnable()) {
                factories.put(modelEnum.getCode(),
                        (AiModelStrategy) applicationContext.getBean(modelEnum.getModelStrategy()));
            }
        }
    }

    public AiModelStrategy getAiModelStrategy(AiModelEnum modelEnum) {
        return factories.get(modelEnum.getCode());
    }
}
